package br.com.cnpv.modelo.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

import br.com.cnpv.modelo.acesso.idao.IPerfilDAO;
import br.com.cnpv.modelo.entity.Perfil;

public class PerfilDAO implements IPerfilDAO{

	@SuppressWarnings("unchecked")
	@Override
	public List<Perfil> buscar(Perfil perfil, Session session) throws HibernateException {
		
		Query query = session.getNamedQuery("Perfil.buscar");
		query.setString("nmPerfil", "%"+perfil.getNmPerfil()+"%");
		
		return query.list();
	}

	public void saveOrUpdate(Perfil perfil, Session session)
			throws HibernateException {
		session.merge(perfil);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Perfil> listar(Session session) throws HibernateException 
	{
		Query query = session.getNamedQuery("Perfil.listar");
		return query.list();
	}
}